class SumOfMultiples {
    private int[] set;
    private int number;

    SumOfMultiples(int number, int[] set) {
        this.number = number;
        this.set = set;
    }

    int getSum() {
        int result = 0;
        int[] flag = new int[this.number+1];
        for (int aSet : this.set) {
            int tmp;
            int j = 1;
            while (true) {
                tmp = aSet * j;
                if (tmp >= this.number)
                    break;

                if (flag[tmp] == 0) {
                    result += tmp;
                    flag[tmp] = 1;
                }
                j++;
            }
        }

        return result;
    }
}
